﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Equipment;
using MVC_System.DTO.GualityGroup;
using MVC_System.DTO.Workshop;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class WorkshopsController : Controller
    {
        private readonly IConfiguration _configuration;
        public WorkshopsController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult WorkshopShowView()
        {
            return View();
        }
        /// <summary>
        ///车间显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsShow(WorkshopDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "Workshop/api/Workshops/Get?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&workshopNo=" + dto.workshopNo + "&workshopName=" + dto.workshopName + "&workshopState=" + dto.workshopState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 车间添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsAdd(WorkshopAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Workshops/Add";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 车间删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsDelete(WorkshopDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Workshops/Deletes";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 车间批量删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsPiDelete(WorkshopDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Workshops/Delete";
            var list = "{\"workshopId\":" + dto.Data + "}";
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }
        /// <summary>
        /// 车间反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsFinds(WorkshopModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"] + "Workshop/api/Workshops/GetById?workshopId=" + dto.workshopId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 车间修改
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>1
        public async Task<ActionResult> WorkshopsUpdate(WorkshopUpdateDTO obj1, string token)
        { 
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url =_configuration["Url"] + "Workshop/api/Workshops/Update";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 车间状态修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> WorkshopsState(WorkshopModelDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            //string url ="http://localhost:17162/api/Workshops/WorkshopStateUpdate?workshopId=" + dto.workshopId;13151317982
            string url = _configuration["Url"] + "Workshop/api/Workshops/WorkshopStateUpdate?workshopId=" + dto.workshopId;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        ///车间查看
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkshopsFind()
        {
            return View();
        }
    }
}
